package dtm;

import org.junit.jupiter.api.Test;
import tm.EnumDirection;
import tm.TMConfiguration;
import tm.TMRule;
import tm.Tape;

import java.util.Arrays;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * @author haoly
 * @title DTMRulebookTest
 * @date 2025/4/23 14:31
 * @description 确定性图灵机规则集测试类
 */
public class DTMRulebookTest {
    @Test
    public void testNextConfiguration(){
        List<TMRule<Integer>> rules = Arrays.asList(
                new TMRule<>(1, '0', 2, '1', EnumDirection.RIGHT),
                new TMRule<>(1, '1', 1, '0', EnumDirection.LEFT),
                new TMRule<>(1, '_', 2, '1', EnumDirection.RIGHT),
                new TMRule<>(2, '0', 2, '0', EnumDirection.RIGHT),
                new TMRule<>(2, '1', 2, '1', EnumDirection.RIGHT),
                new TMRule<>(2, '_', 3, '_', EnumDirection.LEFT)
        );

        DTMRulebook<Integer> rulebook = new DTMRulebook<>(rules);

        char blankChar = '_';
        Tape tape = new Tape(List.of('1','0','1'), '1', List.of(), blankChar);

        TMConfiguration<Integer> configuration = new TMConfiguration<>(1, tape);
        System.out.println(configuration);

        configuration = rulebook.nextConfiguration(configuration);
        assertEquals(1, configuration.getState());
        assertEquals('1', configuration.getTape().getMiddle());
        System.out.println(configuration);

        configuration = rulebook.nextConfiguration(configuration);
        assertEquals(1, configuration.getState());
        assertEquals('0', configuration.getTape().getMiddle());
        System.out.println(configuration);
    }
}
